<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平时成绩管理系统-课程表管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-schedule"
     style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">班级</label>
        <div class="layui-input-block">
            <select name="clazzId" id="clazzId"></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">课程</label>
        <div class="layui-input-block">
            <select name="courseId" id="courseId" lay-filter="courseId"></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">授课教师</label>
        <div class="layui-input-block">
            <select name="teacherId" id="teacherId"></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学期</label>
        <div class="layui-input-block">
            <select name="scheduleType">
                <option value=""></option>
                <option value="0">上学期</option>
                <option value="1">下学期</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学年</label>
        <div class="layui-input-block">
            <input type="text" name="scheduleYear" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上课时间起</label>
        <div class="layui-inline">
            <input type="text" class="layui-input" name="scheduleTimeStart" id="scheduleTimeStart">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上课时间止</label>
        <div class="layui-inline">
            <input type="text" class="layui-input" name="scheduleTimeEnd" id="scheduleTimeEnd">
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-schedule-submit" id="LAY-schedule-submit" value="确认">
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js"></script>
<!--班级option选项模板-->
<script id="optionClazzId" type="text/html">
    <option value=""></option>
    {{#  layui.each(d.data, function(index, clazz){  }}
    <option value="{{clazz.clazzId}}">
        {{clazz.clazzYear}}级 {{clazz.clazzName}}
    </option>
    {{#  }); }}
    {{#  if(d.data.length === 0){ }}
    无数据
    {{#  } }}
</script>

<!--课程option选项模板-->
<script id="optionCourse" type="text/html">
    <option value=""></option>
    {{#  layui.each(d.data, function(index, course){  }}
    <option value="{{course.courseId}}">
        {{course.courseId}}： {{course.courseName}}
    </option>
    {{#  }); }}
    {{#  if(d.data.length === 0){ }}
    无数据
    {{#  } }}
</script>

<!--授课教师选项模板-->
<script id="optionTeacher" type="text/html">
    <option value=""></option>
    {{#  layui.each(d.data, function(index, course){  }}
    <option value="{{course.teacherId}}">
        {{course.teacherId}}： {{course.teacherName}}
    </option>
    {{#  }); }}
    {{#  if(d.data.length === 0){ }}
    无数据
    {{#  } }}
</script>
<script>
    layui.config({
        base: '../../layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'laytpl','laydate'], function () {
        let $ = layui.$
            , setter = layui.setter
            , laytpl = layui.laytpl
            , laydate = layui.laydate
            , form = layui.form;


        /*时间初始化*/

        laydate.render({
            elem: '#scheduleTimeStart'
            , type: 'datetime'
            , trigger: 'click'
        });

        laydate.render({
            elem: '#scheduleTimeEnd'
            , type: 'datetime'
            , trigger: 'click'
        });

        /*
        加载班级信息
        加载课程信息
        */
        $(function () {
            $.ajax({
                url: setter.baseUrl + '/clazz/ins',
                dataType: "json",
                type: "get",
                contentType: 'application/json',
                xhrFields: {
                    withCredentials: true
                },
                success: function (res) {
                    if (res.code === 200) {
                        let getTpl = optionClazzId.innerHTML
                            , view = document.getElementById('clazzId');
                        laytpl(getTpl).render(res, function (html) {
                            view.innerHTML = html;
                        });
                        form.render(); //更新全部
                    } else {
                        layer.msg("失败");
                    }

                },
                error: function (e) {
                    layer.msg("失败");
                }
            });
            $.ajax({
                url: setter.baseUrl + '/course/ins',
                dataType: "json",
                type: "get",
                contentType: 'application/json',
                xhrFields: {
                    withCredentials: true
                },
                success: function (res) {
                    if (res.code === 200) {
                        let getTpl = optionCourse.innerHTML
                            , view = document.getElementById('courseId');
                        laytpl(getTpl).render(res, function (html) {
                            view.innerHTML = html;
                        });
                        form.render(); //更新全部
                    } else {
                        layer.msg("失败");
                    }

                },
                error: function (e) {
                    layer.msg("失败");
                }
            });
        });

        /*
               根据选中的课程加载授课的教师
            */
        form.on('select(courseId)', function(){
            $.ajax({
                url: setter.baseUrl + '/course/ins',
                dataType: "json",
                type: "get",
                contentType: 'application/json',
                xhrFields: {
                    withCredentials: true
                },
                data: {'courseId': $('#courseId').val()},
                success: function (res) {
                    if (res.code === 200) {
                        let getTpl = optionTeacher.innerHTML
                            , view = document.getElementById('teacherId');
                        laytpl(getTpl).render(res, function (html) {
                            view.innerHTML = html;
                        });
                        form.render(); //更新全部
                    } else {
                        layer.msg("失败");
                    }

                },
                error: function (e) {
                    layer.msg("失败");
                }
            });
        });

    })
</script>
</body>
</html>
